package com.objecteffects.ilmp.web.inject;

import javax.inject.Inject;
import javax.servlet.ServletContext;

import com.silvermindsoftware.sg.guice.DefaultGuiceInjectorFactory;
import com.silvermindsoftware.sg.guice.GuiceInjectorFactory;

import com.google.inject.Injector;
import com.google.inject.persist.PersistService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Rusty Wright
 */
public class CustomInjectorFactory implements GuiceInjectorFactory {
    @SuppressWarnings("unused")
    private final transient Logger log = LoggerFactory
        .getLogger(CustomInjectorFactory.class);

    @Override
    public Injector getInjector(final ServletContext servletContext) {
        final Injector injector =
            new DefaultGuiceInjectorFactory().getInjector(servletContext);

        injector.getInstance(ApplicationInitializer.class);

        return (injector);
    }

    /**
     */
    public static class ApplicationInitializer {
        @Inject
        ApplicationInitializer(final PersistService service) {
            service.start();
        }
    }
}
